//
// @author				mitchell
// @description		020101.html页面的JS打包文件 注意引用顺序
// @lastmodified		$2010-7 - 15$
$(document).ready(function(){
	//answer
	$(".close").click(function(event){
		event.preventDefault();
		$(".fruit,#mask").hide();
	});
	
	$(document).keyup(function(e){
		if(e.which == 27){
			var temp= $(".fruit").is(":visible");//是否可见
			if(!temp){
				return false;
			}
			$(".fruit,#mask").hide();
		}
	});
	
	$(".answer_but_ajax").click(function(event){
		event.preventDefault();
		$("#mask").show();
		var askid = $(this).attr("askid");
		var title = $(this).attr("title");
		var answer = $(".answer_"+askid).html();
		
		var st = $(document).scrollTop();
		$(".fruit").css('top',st+100).show();
		$("#input3").attr('askid',askid);
		$("#hide_askid").val(askid);
		$("#answer").html(answer);
	});
	
	$("#input4").click(function(event){
		event.preventDefault();
		var url =js_context.base_url+"ajax/answer/answer";
		var askid = $(this).attr("askid");
		var answer = $(".answer_content_ajax_"+askid).val();
		$.get(url,{ "answer" : answer,'askid' : askid}, function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('回复失败');
				return false;
			}
			if(data.error == 'notlogin'){
				alert('请先登录!');
				return false;
			}
			alert(data.answer);
			self.location = js_context.base_url+'ask/asklist';
		},"json");
		
	});
	
	$(".answerDiv .answer_but").click(function(event){
		event.preventDefault();
		var url = $(this).attr("href");
		var askid = $(this).attr("askid");
		var answer = $(".answer_content_"+askid).val();

		$.get(url,{ "answer" : answer,'askid' : askid}, function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('回复失败');
				return false;
			}
			alert(data.answer);
			self.location = js_context.base_url+'ask/asklist';
		},"json");
		
	});
	
	//ask
	$("#tiwen").click(function(event){
		event.preventDefault();
		$(".ask").show();
	});
	$("#close").click(function(event){
		event.preventDefault();
		$(".ask").hide();
		//$(".fruit").hide();
	});
	$("#ask_sub").click(function(event){
		event.preventDefault();
		var url = js_context.base_url+"ajax/answer/ask";
		var title = $('#title').val();
		var content = $('#content').val();
		if(content == ''){
			alert('请输入您的问题！')
			return false;
		}
		if(content.length < 6){
			alert('请您仔细阐述您的问题！')
			return false;
		}
		$.get(url,{ "title" : title,'content':content}, function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('提交失败');
				return false;
			}
			if(data.error == 'notlogin'){
				alert('请先登录!');
				return false;
			}
			if(data.error=='insertfalse'){
				alert('提交问题失败,页面将马上刷新!');
				self.location.reload;
				return false;
			}
			if(data.error=='time'){
				alert('请您半小时后在提交');
				return false;
			}
			alert(data.content);
			self.location = js_context.base_url+'ask/asklist';
		},"json");
	});
	//user ask 我的问答
	/*$("#unresolved").click(function(){
		event.preventDefault();
		$(this).attr("class","resolved");
		$("#resolved").attr("class","");
		$("#faq").hide();
		$("#qa").show();
	});
	$("#resolved").click(function(event){
		event.preventDefault();
		$(this).attr("class","resolved");
		$("#unresolved").attr("class","");
		$("#qa").hide();
		$("#faq").show();
		
	});
*/
});
